//
//  ViolationCell.swift
//  TrafficViolation
//
//  Created by eaglelive on 2017/5/4.
//  Copyright © 2017年 eaglelive. All rights reserved.
//

import UIKit

class ViolationCell: UITableViewCell {
    var violationCode,violationAddress,score,serviceAmount,violationTime,isReplace,violationState,violationFine: UILabel!
    var checkBox:UIButton!
    override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        self.selectionStyle = UITableViewCellSelectionStyle.none
        self.backgroundColor = tableBgColor
        self.setupMainView()
    }
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
}
extension ViolationCell{
    func setupMainView(){
        // 背景view
        let backgroundView = UIView()
        backgroundView.layer.borderColor = colorFromHex(0xeeeeee).cgColor
        backgroundView.layer.borderWidth = 1
        backgroundView.layer.cornerRadius = 5
        backgroundView.layer.masksToBounds = true
        backgroundView.backgroundColor = UIColor.white
        self.addSubview(backgroundView)
        backgroundView.snp.makeConstraints { (make) in
            make.left.equalTo(self).offset(5)
            make.top.equalTo(self).offset(5)
            make.right.equalTo(self).offset(-5)
            make.bottom.equalTo(self)
        }
        //订单提交时间
        violationTime = UILabel()
        violationTime.font = UIFont.systemFont(ofSize: 11)
        backgroundView.addSubview(violationTime)
        violationTime.snp.makeConstraints { (make) in
            make.height.equalTo(25)
            make.top.equalTo(backgroundView).offset(5)
            make.left.equalTo(backgroundView).offset(10)
            make.width.equalTo(violationTime.snp.width)
        }
        //状态
        isReplace = UILabel()
        isReplace.textColor = appMainColor
        isReplace.font = UIFont.systemFont(ofSize: 11)
        backgroundView.addSubview(isReplace)
        isReplace.snp.makeConstraints { (make) in
            make.top.equalTo(backgroundView).offset(6)
            make.right.equalTo(backgroundView).offset(-10)
            make.height.equalTo(25)
        }
        //长分割线
        let longSeparator = UILabel()
        longSeparator.backgroundColor = UIColor(red: 190/255.0, green: 220/255.0, blue: 240/255.0, alpha: 1.0)
        backgroundView.addSubview(longSeparator)
        longSeparator.snp.makeConstraints { (make) in
            make.height.equalTo(1)
            make.top.equalTo(violationTime.snp.bottom)
            make.left.equalTo(backgroundView).offset(10)
            make.right.equalTo(backgroundView).offset(-10)
        }
        //复选框
        checkBox = UIButton()
        checkBox.setImage(UIImage(named: "checked"), for: .selected)
        checkBox.setImage(UIImage(named: "check"), for: .normal)
        checkBox.setImage(UIImage(named: "disabled"), for: .disabled)
        backgroundView.addSubview(checkBox)
        checkBox.snp.makeConstraints { (make) in
            make.height.width.equalTo(25)
            make.top.equalTo(longSeparator.snp.bottom)
            make.left.equalTo(backgroundView).offset(10)
        }
        //违规地址
        violationAddress = UILabel()
        violationAddress.font = UIFont.systemFont(ofSize: 11)
        violationAddress.lineBreakMode = .byTruncatingTail
        backgroundView.addSubview(violationAddress)
        violationAddress.snp.makeConstraints { (make) in
            make.top.equalTo(longSeparator.snp.bottom)
            make.left.equalTo(backgroundView).offset(35)
            make.right.equalTo(backgroundView).offset(-50)
            make.height.equalTo(25)
        }
        //扣分情况
        score = UILabel()
        score.font = UIFont.systemFont(ofSize: 11)
        score.textColor = UIColor.gray
        backgroundView.addSubview(score)
        score.snp.makeConstraints { (make) in
            make.top.equalTo(longSeparator.snp.bottom)
            make.right.equalTo(backgroundView).offset(-10)
            make.height.equalTo(25)
        }
        
        //违规代码
        violationCode = UILabel()
        violationCode.font = UIFont.systemFont(ofSize: 10)
        violationCode.textColor = UIColor.gray
        violationCode.lineBreakMode = .byTruncatingTail
        backgroundView.addSubview(violationCode)
        violationCode.snp.makeConstraints { (make) in
            make.top.equalTo(violationAddress.snp.bottom)
            make.left.equalTo(backgroundView).offset(35)
            make.right.equalTo(backgroundView).offset(-10)
            make.height.equalTo(25)
        }
        //短分割线
        let shortSeparator = UILabel()
        shortSeparator.backgroundColor = UIColor(red: 190/255.0, green: 220/255.0, blue: 240/255.0, alpha: 1.0)
        backgroundView.addSubview(shortSeparator)
        shortSeparator.snp.makeConstraints { (make) in
            make.height.equalTo(1)
            make.top.equalTo(violationCode.snp.bottom)
            make.left.equalTo(backgroundView).offset(30)
            make.right.equalTo(backgroundView).offset(-5)
        }
        //是否处理
        violationState = UILabel()
        violationState.textColor = appMainColor
        violationState.font = UIFont.systemFont(ofSize: 11)
        backgroundView.addSubview(violationState)
        violationState.snp.makeConstraints { (make) in
            make.bottom.equalTo(backgroundView)
            make.left.equalTo(backgroundView).offset(30)
            make.height.equalTo(25)
            make.width.equalTo(75)
        }
        //服务费
        serviceAmount = UILabel()
        serviceAmount.font = UIFont.systemFont(ofSize: 11)
        backgroundView.addSubview(serviceAmount)
        serviceAmount.snp.makeConstraints { (make) in
            make.bottom.equalTo(backgroundView)
            make.left.equalTo(backgroundView).offset(105)
            make.height.equalTo(25)
        }
        //罚款
        violationFine = UILabel()
        violationFine.font = UIFont.systemFont(ofSize: 11)
        backgroundView.addSubview(violationFine)
        violationFine.snp.makeConstraints { (make) in
            make.bottom.equalTo(backgroundView)
            make.right.equalTo(backgroundView).offset(-10)
            make.height.equalTo(25)
        }
    }
    func configCellDateWithModel(model:ViolationModel) {
        violationTime.text = model.time
        isReplace.text = "可代办" //model.canhandle
        violationAddress.text = model.address
        violationCode.text = model.content
        score.text = "扣 \(model.score) 分"
        serviceAmount.text = "服务费：￥\(model.samount)"
        violationFine.text = "罚款：￥\(model.price)"
    }
}
